'''
Módulo base da estrutura topológica do sistema 

@author: hanniel
'''
from math import sqrt
import Base.Particle as Particle

class Topology:
    
    """
    Cada primitiva topológica tem como base uma estrutura geométrica e um Patch, que definirá como
    a primitiva se comportará no sistema.
    """

    def __init__(self):
        
        self.topology_construction_matrix=[]

def add_particle():
    
    pass
    
def add_boundary(topology,system,geometry,patch):
        
    '''
    ex. uso: topologia = Topology.Topology()
             sistema=System.System()
             geometria=Geometry.Geometry()
             
             p1,p2,p3,p4=...
             linha1=Geometry.Line([p1,p2],geometria)
             linha2=Geometry.Line([p3,p4],geometria)
             linha3=Geometry.Line([p1,p3],geometria)
             linha4=Geometry.Line([p2,p4],geometria)
             
             Wall=Patches.Wall(topology=topologia,slip_conditions='no_slip',exist_time=[0,10],moving_velocity=[0,0])
             In=Patches.Inlet(topology=topologia,exist_time=[0,10],rate_value=1e-2,rate_basis='mass', direction='-y')
             
             add_boundary(topologia,sistema,geometria,Wall)
    '''
        
    if geometry.specie=='LINE':
            
        dx=abs(geometry.x-geometry.xo)
        dy=abs(geometry.y-geometry.yo)
        d=sqrt(dx**2+dy**2)
        
        nparticles=round(d/(2*system.particle_array[0].r))
        hx=dx/nparticles
        hy=dy/nparticles
        
        if patch.name in ['BLOCKAGE','WALL']:
            
            for i in range(nparticles):
                '''(self, fluid, mobility,boundary,initial_position, initial_velocity, initial_temperature, initial_pressure):
                '''
                pxo=geometry.xo+i*hx+system.particle_array[0].r
                pyo=geometry.yo+i*hy+system.particle_array[0].r
                system.particle_array.append(Particle.Particle(fluid='',static='yes',boundary=patch,initial_position=[pxo,pyo],initial_velocity=patch.moving_velocity,initial_temperature=patch.temperature,initial_pressure=0.0))
            
        if patch.name in ['INLET','OUTLET']:
            
            if patch.name=='INLET':
                
                system.inlet_array.append(patch)
            
            if patch.name=='OUTLET':
                
                system.outlet_array.append(patch)
        
    if geometry.specie=='ARC':
            
        pass
        
        
        
        
        


        
        
    
    
        
        